//
//  DIYButton.m
//  Eyes
//
//  Created by 邓芮 on 15/11/5.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "DIYButton.h"
@interface DIYButton ()
{
    CGFloat width;
}
@end

@implementation DIYButton

- (void)setFrame:(CGRect)frame
{
    width = frame.size.height;
    self.iconImageView.frame = CGRectMake(5 * KWidth / 414, 0, width, width);
    [self addSubview:_iconImageView];
    
    self.textLabel.frame = CGRectMake(width + 10 * KWidth / 414 , 0, frame.size.width - width - 10 * KWidth / 414, width);
    [self addSubview:_textLabel];
    
    self.selectIconImageView.frame = self.iconImageView.frame;
    self.selectIconImageView.hidden = YES;
    [self addSubview:_selectIconImageView];
    
    //调用父类的方法
    [super setFrame:frame];
}


#pragma mark -  selectState
- (void)setSelected:(BOOL)selected
{
    
    [super setSelected:selected];
    if (selected)
    {
        _iconImageView.hidden = YES;
        _selectIconImageView.hidden = NO;
    }
    else
    {
        _iconImageView.hidden = NO;
        _selectIconImageView.hidden = YES;
    }

    
}

- (UIImageView *)iconImageView{
    if (_iconImageView == nil) {
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, width)];
    }
    return _iconImageView;
}

- (UIImageView *)selectIconImageView{
    if (_selectIconImageView == nil) {
        self.selectIconImageView = [[UIImageView alloc]initWithFrame:self.iconImageView.frame];
    }
    return _selectIconImageView;
}

- (UILabel *)textLabel{
    if (_textLabel == nil) {
        self.textLabel = [[UILabel alloc]initWithFrame:CGRectMake(width + 5 , 0, self.frame.size.width - width - 5, width)];
    }
    return _textLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
